<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>

<!DOCTYPE html>
<head>
    <title>基础参数设置</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gbk" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=10,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <style>
        .form-horizontal{
            font-family: Microsoft yahei,Helvetica Neue,Helvetica,PingFang SC,Tahoma,Arial,sans-serif;
        }
        input {
            background-color: #ffffff;
            height: 20px;
            padding: 4px 6px;
            margin-bottom: 10px;
            font-size: 13px;
            line-height: 20px;
            color: #555555;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            border-radius: 2px;
            vertical-align: middle;
            border: 1px solid #ccc;
        }
        legend h5{
            font-size: 13pt;
            margin-left: 20px;
        }
    </style>
</head>
<body>
<link rel="stylesheet" type="text/css" href="../../css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="../../css/enterpriseManage/weixinqy.css">
<script type="text/javascript" src="../../js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="../../js/unslider.min.js"></script>
<script src="/lib/layer/layer.js?20201106"></script>
<div>
    <form class="form-horizontal">
        <fieldset>
            <legend><h5>基础参数设置</h5></legend>
            <div class="control-group">
                <label class="control-label" for="inputAppId">WeLinkAppId</label>
                <div class="controls">
                    <input  id="inputAppId" placeholder="appKey" value="" name="weLinkAppId">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="inputSecret">WeLinkAppSecret</label>
                <div class="controls">
                    <input  class="span6" id="inputSecret" placeholder="Secret" value="" name="weLinkAppSecret">
                </div>
            </div>
            <div class="control-group">
                <div class="controls">
                    <button type="button" class="btn" id="btn" >保存</button>
                    <button id="connect-btn" type="button" class="btn btn-warning" style="margin-left: 5px;display: none" v-by=0>测试连接</button>
                    <span id="connect-msg"></span>
                </div>
            </div>
        </fieldset>

    </form>
</div>
<script type="text/javascript">


    $(function(){
        ajax();

        var i=0;
        function inputcheck(name ,val){
            if(val==undefined){
                return;
            }
            $('[name="'+name+'"]').val(val)
        }

        function ajax() {
            $.ajax({
                url:'/weLink/getWeLinkConfig',
                type:'get',
                dataType:'json',
                success:function(res){
                    if(res.flag){
                        inputcheck('weLinkAppId',res.data.weLinkAppId);
                        inputcheck('weLinkAppSecret',res.data.weLinkAppSecret);
                    }
                }
            });
        }


        $("#connect-btn").click(function(){
            $.ajax({
                url:'/weLink/weLinkContent',
                type:'POST',
                async:false,
                dataType:'json',
                success:function (res) {
                    if(res.flag){
                        $("#connect-msg").addClass("text-success").html("连接成功！");
                    }else{
                        $("#connect-msg").removeClass("text-success").addClass("text-error").html("连接失败，请稍后尝试！");
                    }
                }
            })
        });

        $('#btn').click(function(){
            var weLinkAppId= $('[name="weLinkAppId"]').val();
            var weLinkAppSecret= $('[name="weLinkAppSecret"]').val();

            $.ajax({
                url:'/weLink/setWeLinkConfig',
                type:'POST',
                data:{
                    weLinkAppId:weLinkAppId,
                    weLinkAppSecret:weLinkAppSecret
                },
                dataType:'json',
                success:function (res) {
                    if(res.flag){
                        ajax();
                        $('#connect-btn').css('display','inline-block')
                        layer.msg("保存成功", {icon: 1})
                    }
                }
            })
        })
    });
</script>
</body>
</html>